#ifndef AVALON_ASYNCHRONOUSRESULTTASK_HPP
#define AVALON_ASYNCHRONOUSRESULTTASK_HPP
#include "Avalon/Threading/AsyncCallDetail.hpp"
#include "Avalon/Threading/Threading.hpp"

namespace Avalon {
namespace Threading {

  //! Invokes a function asynchronously.
  /*!
    \param function The function to invoke.
    \return An Async storing the <i>function</i>'s return value.
  */
  template<typename F>
  typename Async<typename boost::function_traits<typename
    boost::remove_pointer<F>::type>::result_type>::Ptr AsyncCall(
      const F& function) {
    typedef typename boost::function_traits<
      typename boost::remove_pointer<F>::type>::result_type ReturnType;
    typename AsyncOwner<ReturnType>::Ptr result(
      AsyncOwner<ReturnType>::Create());
    Task* task = Detail::CreateCallTask(result, function);
    task->Enqueue();
    return result;
  }
}
}

#endif // AVALON_ASYNCHRONOUSRESULTTASK_HPP
